package fms.models;
 
import java.util.List;
 
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import fms.classes.Form2;
 
 
public class Form2DAO {
 
    private SqlSessionFactory sqlSessionFactory;
 
    public Form2DAO(){
    	try{
    		sqlSessionFactory = MyBatisSqlConnection.getSqlSessionFactory();
    	}catch(Exception e) {
    		System.out.println("failed to get sqlSessionFactory");
    	}
    }
 
    /**Returns the list of all Form2 instances from the database*/
    @SuppressWarnings("unchecked")
    public List<Form2> selectAll(){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            List<Form2> list = session.selectList("Form2.getAll");
            return list;
        } finally {
            session.close();
        }
    }
 
    /**Returns a Form2 instance from the database*/
    public Form2 selectById(int promissory_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            Form2 form2 = (Form2) session.selectOne("Form2.getById", promissory_no);
            return form2;
        } finally {
            session.close();
        }
    }
 
    /**Returns a Form2 instance from the database
    public Form2 getAllPending(String status){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            Form2 form2 = (Form2) session.selectOne("Form2.getAllPending", status);
            return form2;
        } finally {
            session.close();
        }
    }*/
    
    /**Updates an instance of Form2 in the database*/
    public void update(Form2 form2){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.update("Form2.update", form2);
            session.commit();
        } finally {
            session.close();
        }
    }
    
    /**Updates the status of Form2 in the database
    public void updateStatus(int promissory_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.update("Form2.updateStatus", promissory_no);
            session.commit();
        } finally {
            session.close();
        }
    }*/
 
    /** Insert an instance of Form2 into the database*/
    public void insert(Form2 form2){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.insert("Form2.insert", form2);
            session.commit();
        } finally {
            session.close();
        }
    }
 
    /** Delete an instance of Form2 from the database*/
    public void delete(int promissory_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.delete("Form2.deleteById", promissory_no);
            session.commit();
        } finally {
            session.close();
        }
    }
}